import Vue from "vue";
import {request} from "../../../util/request"
import "../../../common/common.less";
import dialog from "../../../util/dialog.js";
new Vue({
    el:"#louie",
    data:{
        web_icon_input:null,
        web_name:"",
        web_icon:"",
        web_description:""
    },
    computed:{
        data:function(){
            let data = {
                web_name:this.web_name,
                web_icon:this.web_icon,
                web_description:this.web_description
            }
            return data;
        }
    },
    created:function(){
        this.get();
    },
    mounted:function(){
        this.web_icon_input = this.$refs.web_icon.querySelector("input");
        this.web_icon_input.readOnly = true;
    },
    methods:{
        /**
         * 获取参数
         */
        get(){
            request("setting/find",{
                return:["web_name","web_icon","web_description"]
            })
                .then((res)=>{
                    console.log(res)
                    if(res.data.status === "success"){
                        let data = res.data.data;
                        this.web_name = data.web_name;
                        this.web_icon = data.web_icon;
                        this.web_icon_input.value = data.web_icon;
                        this.web_icon_input.parentNode.parentNode.querySelector("img").src = data.web_icon_url;
                        this.web_description = data.web_description;
                    }
                });
        },
        /**
         * 设置参数
         */
        submit(){
            this.web_icon = this.web_icon_input.value;
            request("setting/set",{
                data:this.data
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        dialog.alert(this,"设置成功");
                    }else{
                        dialog.alert(this,"设置失败");
                    }
                });
        }
    }
});